package com.ibeeking.found.open.b.rest.service.impl;

import com.ibeeking.found.open.api.common.dto.GoodsInfoDTO;
import com.ibeeking.found.open.api.common.dto.GoodsListDTO;
import com.ibeeking.found.open.api.common.query.GoodsListQuery;
import com.ibeeking.found.open.api.feign.GoodsFeignClient;
import com.ibeeking.found.open.b.rest.service.IGoodsService;
import com.ibeeking.found.open.b.rest.service.ISystemService;
import com.ibeeking.nematos.utils.base.page.Page;
import com.ibeeking.nematos.utils.result.ResponseResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName GoodsServiceImpl
 * @Description
 * @Author ibeeking
 * @Date 2021-06-14 19:17
 **/
@Service
public class GoodsServiceImpl implements IGoodsService {

    @Resource
    private GoodsFeignClient goodsFeignClient;
    @Resource
    private ISystemService systemServiceImpl;

    @Override
    public Page<GoodsListDTO> goodsList(GoodsListQuery query) {
        query.setShopId(systemServiceImpl.queryShopIdByShopCode(query.getShopCode()));
        ResponseResult<Page<GoodsListDTO>> responseResult = goodsFeignClient.apiGoodsPageList(query);
        if (null == responseResult || null == responseResult.getData()) {
            return new Page<>();
        }
        return responseResult.getData();
    }

    @Override
    public GoodsInfoDTO goodsInfo(Long goodsId) {
        ResponseResult<GoodsInfoDTO> responseResult = goodsFeignClient.apiGoodsInfo(goodsId);
        if (null == responseResult) {
            return new GoodsInfoDTO();
        }
        return responseResult.getData();
    }
}
